package com.android.utils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.CharacterStyle;
import android.text.style.ForegroundColorSpan;
import android.text.style.ImageSpan;

import com.android.myj.R;


public class TextUtil {
	
	public static Map<String,Integer> faceNameToDrawableId = new HashMap<String, Integer>();
	public static Map<String,String> drawableIdToFaceName = new HashMap<String, String>();
	
	static{
		faceNameToDrawableId.put("调皮", R.drawable.f000);
		faceNameToDrawableId.put("呲牙", R.drawable.f001);
		faceNameToDrawableId.put("惊讶", R.drawable.f002);
		faceNameToDrawableId.put("难过", R.drawable.f003);
		faceNameToDrawableId.put("酷", R.drawable.f004);
		faceNameToDrawableId.put("冷汗", R.drawable.f005);
		faceNameToDrawableId.put("抓狂", R.drawable.f006);
		faceNameToDrawableId.put("吐", R.drawable.f007);
		faceNameToDrawableId.put("偷笑", R.drawable.f008);
		faceNameToDrawableId.put("可爱", R.drawable.f009);
		faceNameToDrawableId.put("白眼", R.drawable.f010);
		faceNameToDrawableId.put("傲慢", R.drawable.f011);
		faceNameToDrawableId.put("微笑", R.drawable.f012);
		faceNameToDrawableId.put("撇嘴", R.drawable.f013);
		faceNameToDrawableId.put("色", R.drawable.f014);
		faceNameToDrawableId.put("发呆", R.drawable.f015);
		faceNameToDrawableId.put("得意", R.drawable.f016);
		faceNameToDrawableId.put("流泪", R.drawable.f017);
		faceNameToDrawableId.put("害羞", R.drawable.f018);
		faceNameToDrawableId.put("嘘", R.drawable.f019);
		faceNameToDrawableId.put("困", R.drawable.f020);
		
		faceNameToDrawableId.put("尴尬", R.drawable.f021);
		faceNameToDrawableId.put("发怒", R.drawable.f022);
		faceNameToDrawableId.put("大哭", R.drawable.f023);
		faceNameToDrawableId.put("流汗", R.drawable.f024);
		faceNameToDrawableId.put("再见", R.drawable.f025);
		faceNameToDrawableId.put("敲打", R.drawable.f026);
		faceNameToDrawableId.put("擦汗", R.drawable.f027);
		faceNameToDrawableId.put("委屈", R.drawable.f028);
		faceNameToDrawableId.put("疑问", R.drawable.f029);
		faceNameToDrawableId.put("睡", R.drawable.f030);
		faceNameToDrawableId.put("亲亲", R.drawable.f031);
		
		faceNameToDrawableId.put("憨笑", R.drawable.f032);
		faceNameToDrawableId.put("调皮", R.drawable.f033);
		faceNameToDrawableId.put("阴险", R.drawable.f034);
		faceNameToDrawableId.put("奋斗", R.drawable.f035);
		faceNameToDrawableId.put("右哼哼", R.drawable.f036);
		faceNameToDrawableId.put("拥抱", R.drawable.f037);
		faceNameToDrawableId.put("坏笑", R.drawable.f038);
		faceNameToDrawableId.put("鄙视", R.drawable.f039);
		faceNameToDrawableId.put("晕", R.drawable.f040);
		faceNameToDrawableId.put("大兵", R.drawable.f041);
		faceNameToDrawableId.put("可怜", R.drawable.f042);
		
		faceNameToDrawableId.put("饥饿", R.drawable.f043);
		faceNameToDrawableId.put("咒骂", R.drawable.f044);
		faceNameToDrawableId.put("抠鼻", R.drawable.f045);
		faceNameToDrawableId.put("鼓掌", R.drawable.f046);
		faceNameToDrawableId.put("糗大了", R.drawable.f047);
		faceNameToDrawableId.put("左哼哼", R.drawable.f048);
		faceNameToDrawableId.put("哈欠", R.drawable.f049);
		faceNameToDrawableId.put("快哭了", R.drawable.f050);
		faceNameToDrawableId.put("吓", R.drawable.f051);
		faceNameToDrawableId.put("闭嘴", R.drawable.f052);
		faceNameToDrawableId.put("惊恐", R.drawable.f053);
		
		faceNameToDrawableId.put("折磨", R.drawable.f054);
		faceNameToDrawableId.put("示爱", R.drawable.f055);
		faceNameToDrawableId.put("爱心", R.drawable.f056);
		faceNameToDrawableId.put("心碎", R.drawable.f057);
		faceNameToDrawableId.put("蛋糕", R.drawable.f058);
		faceNameToDrawableId.put("闪电", R.drawable.f059);
		faceNameToDrawableId.put("炸弹", R.drawable.f060);
		faceNameToDrawableId.put("刀", R.drawable.f061);
		faceNameToDrawableId.put("足球", R.drawable.f062);
		faceNameToDrawableId.put("瓢虫", R.drawable.f063);
		faceNameToDrawableId.put("便便", R.drawable.f064);
		
		faceNameToDrawableId.put("咖啡", R.drawable.f065);
		faceNameToDrawableId.put("饭", R.drawable.f066);
		faceNameToDrawableId.put("猪", R.drawable.f067);
		faceNameToDrawableId.put("玫瑰", R.drawable.f068);
		faceNameToDrawableId.put("凋谢", R.drawable.f069);
		faceNameToDrawableId.put("月亮", R.drawable.f070);
		faceNameToDrawableId.put("太阳", R.drawable.f071);
		faceNameToDrawableId.put("礼物", R.drawable.f072);
		faceNameToDrawableId.put("强", R.drawable.f073);
		faceNameToDrawableId.put("弱", R.drawable.f074);
		faceNameToDrawableId.put("握手", R.drawable.f075);
		
		faceNameToDrawableId.put("胜利", R.drawable.f076);
		faceNameToDrawableId.put("抱拳", R.drawable.f077);
		faceNameToDrawableId.put("勾引", R.drawable.f078);
		faceNameToDrawableId.put("拳头", R.drawable.f079);
		faceNameToDrawableId.put("差劲", R.drawable.f080);
		faceNameToDrawableId.put("爱你", R.drawable.f081);
		faceNameToDrawableId.put("NO", R.drawable.f082);
		faceNameToDrawableId.put("OK", R.drawable.f083);
		faceNameToDrawableId.put("爱情", R.drawable.f084);
		faceNameToDrawableId.put("飞吻", R.drawable.f085);
		faceNameToDrawableId.put("跳跳", R.drawable.f086);
		
		faceNameToDrawableId.put("发抖", R.drawable.f087);
		faceNameToDrawableId.put("怄火", R.drawable.f088);
		faceNameToDrawableId.put("转圈", R.drawable.f089);
		faceNameToDrawableId.put("磕头", R.drawable.f090);
		faceNameToDrawableId.put("回头", R.drawable.f091);
		faceNameToDrawableId.put("跳绳", R.drawable.f092);
		faceNameToDrawableId.put("挥手", R.drawable.f093);
		faceNameToDrawableId.put("激动", R.drawable.f094);
		faceNameToDrawableId.put("街舞", R.drawable.f095);
		faceNameToDrawableId.put("献吻", R.drawable.f096);
		faceNameToDrawableId.put("左太极", R.drawable.f097);
		
		faceNameToDrawableId.put("右太极", R.drawable.f098);
		faceNameToDrawableId.put("菜刀", R.drawable.f099);
		faceNameToDrawableId.put("西瓜", R.drawable.f100);
		faceNameToDrawableId.put("啤酒", R.drawable.f101);
		faceNameToDrawableId.put("骷髅", R.drawable.f102);
		faceNameToDrawableId.put("篮球", R.drawable.f103);
		faceNameToDrawableId.put("乒乓", R.drawable.f104);
	}
	
	static{
		drawableIdToFaceName.put("h000","调皮");
		drawableIdToFaceName.put("h001","呲牙");
		drawableIdToFaceName.put("h002","惊讶");
		drawableIdToFaceName.put("h003","难过");
		drawableIdToFaceName.put("h004","酷");
		drawableIdToFaceName.put("h005","冷汗");
		drawableIdToFaceName.put("h006","抓狂");
		drawableIdToFaceName.put("h007","吐");
		drawableIdToFaceName.put("h008","偷笑");
		drawableIdToFaceName.put("h009","可爱");
		drawableIdToFaceName.put("h010","白眼");
		drawableIdToFaceName.put("h011","傲慢");
		drawableIdToFaceName.put("h012","微笑");
		drawableIdToFaceName.put("h013","撇嘴");
		drawableIdToFaceName.put("h014","色");
		drawableIdToFaceName.put("h015","发呆");
		drawableIdToFaceName.put("h016","得意");
		drawableIdToFaceName.put("h017","流泪");
		drawableIdToFaceName.put("h018","害羞");
		drawableIdToFaceName.put("h019","嘘");
		drawableIdToFaceName.put("h020","困");
		
		drawableIdToFaceName.put("h021","尴尬");
		drawableIdToFaceName.put("h022","发怒");
		drawableIdToFaceName.put("h023","大哭");
		drawableIdToFaceName.put("h024","流汗");
		drawableIdToFaceName.put("h025","再见");
		drawableIdToFaceName.put("h026","敲打");
		drawableIdToFaceName.put("h027","擦汗");
		drawableIdToFaceName.put("h028","委屈");
		drawableIdToFaceName.put("h029","疑问");
		drawableIdToFaceName.put("h030","睡");
		drawableIdToFaceName.put("h031","亲亲");
		
		drawableIdToFaceName.put("h032","憨笑");
		drawableIdToFaceName.put("h033","调皮");
		drawableIdToFaceName.put("h034","阴险");
		drawableIdToFaceName.put("h035","奋斗");
		drawableIdToFaceName.put("h036","右哼哼");
		drawableIdToFaceName.put("h037","拥抱");
		drawableIdToFaceName.put("h038","坏笑");
		drawableIdToFaceName.put("h039","鄙视");
		drawableIdToFaceName.put("h040","晕");
		drawableIdToFaceName.put("h041","大兵");
		drawableIdToFaceName.put("h042","可怜");
		
		drawableIdToFaceName.put("h043","饥饿");
		drawableIdToFaceName.put("h044","咒骂");
		drawableIdToFaceName.put("h045","抠鼻");
		drawableIdToFaceName.put("h046","鼓掌");
		drawableIdToFaceName.put("h047","糗大了");
		drawableIdToFaceName.put("h048","左哼哼");
		drawableIdToFaceName.put("h049","哈欠");
		drawableIdToFaceName.put("h050","快哭了");
		drawableIdToFaceName.put("h051","吓");
		drawableIdToFaceName.put("h052","闭嘴");
		drawableIdToFaceName.put("h053","惊恐");
		
		drawableIdToFaceName.put("h054","折磨");
		drawableIdToFaceName.put("h055","示爱");
		drawableIdToFaceName.put("h056","爱心");
		drawableIdToFaceName.put("h057","心碎");
		drawableIdToFaceName.put("h058","蛋糕");
		drawableIdToFaceName.put("h059","闪电");
		drawableIdToFaceName.put("h060","炸弹");
		drawableIdToFaceName.put("h061","刀");
		drawableIdToFaceName.put("h062","足球");
		drawableIdToFaceName.put("h063","瓢虫");
		drawableIdToFaceName.put("h064","便便");
		
		drawableIdToFaceName.put("h065","咖啡");
		drawableIdToFaceName.put("h066","饭");
		drawableIdToFaceName.put("h067","猪");
		drawableIdToFaceName.put("h068","玫瑰");
		drawableIdToFaceName.put("h069","凋谢");
		drawableIdToFaceName.put("h070","月亮");
		drawableIdToFaceName.put("h071","太阳");
		drawableIdToFaceName.put("h072","礼物");
		drawableIdToFaceName.put("h073","强");
		drawableIdToFaceName.put("h074","弱");
		drawableIdToFaceName.put("h075","握手");
		
		drawableIdToFaceName.put("h076","胜利");
		drawableIdToFaceName.put("h077","抱拳");
		drawableIdToFaceName.put("h078","勾引");
		drawableIdToFaceName.put("h079","拳头");
		drawableIdToFaceName.put("h080","差劲");
		drawableIdToFaceName.put("h081","爱你");
		drawableIdToFaceName.put("h082","NO");
		drawableIdToFaceName.put("h083","OK");
		drawableIdToFaceName.put("h084","爱情");
		drawableIdToFaceName.put("h085","飞吻");
		drawableIdToFaceName.put("h086","跳跳");
		
		drawableIdToFaceName.put("h087","发抖");
		drawableIdToFaceName.put("h088","怄火");
		drawableIdToFaceName.put("h089","转圈");
		drawableIdToFaceName.put("h090","磕头");
		drawableIdToFaceName.put("h091","回头");
		drawableIdToFaceName.put("h092","跳绳");
		drawableIdToFaceName.put("h093","挥手");
		drawableIdToFaceName.put("h094","激动");
		drawableIdToFaceName.put("h095","街舞");
		drawableIdToFaceName.put("h096","献吻");
		drawableIdToFaceName.put("h097","左太极");
		
		drawableIdToFaceName.put("h098","右太极");
		drawableIdToFaceName.put("h099","菜刀");
		drawableIdToFaceName.put("h100","西瓜");
		drawableIdToFaceName.put("h101","啤酒");
		drawableIdToFaceName.put("h102","骷髅");
		drawableIdToFaceName.put("h103","篮球");
		drawableIdToFaceName.put("h104","乒乓");
	}
	
	
	public static SpannableString decorateFaceInStr(SpannableString spannable,List<Map<String,Object>> list,Resources resources){
		int size = list.size();
		Drawable drawable = null;
		if(list!=null&&list.size()>0){
			for(int i=0;i<size;i++){
				Map<String,Object> map = list.get(i);
				drawable = resources.getDrawable(faceNameToDrawableId.get(map.get("faceName")));
				drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight());
				ImageSpan span = new ImageSpan(drawable,ImageSpan.ALIGN_BASELINE);
				spannable.setSpan(span, (Integer)map.get("startIndex"), (Integer)map.get("endIndex"), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			}
		}
		return spannable;
	}
	public static SpannableString decorateVipInStr(SpannableString spannable,List<Map<String,Object>> list,Resources resources){
		int size = list.size();
		Drawable drawable = null;
		if(list!=null&&list.size()>0){
			for(int i=0;i<size;i++){
				Map<String,Object> map = list.get(i);
				drawable = resources.getDrawable(R.drawable.vip);
				drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight());
				ImageSpan span = new ImageSpan(drawable,ImageSpan.ALIGN_BASELINE);
				spannable.setSpan(span, (Integer)map.get("startIndex"), (Integer)map.get("endIndex"), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			}
		}
		return spannable;
	}
	
	public static SpannableString decorateTopicInStr(SpannableString spannable,List<Map<String,Object>> list,Resources resources){
		int size = list.size();
		CharacterStyle foregroundColorSpan=new ForegroundColorSpan(Color.argb(255, 33, 92, 110));
		if(list!=null&&list.size()>0){
			for(int i=0;i<size;i++){
				Map<String,Object> map = list.get(i);
				spannable.setSpan(foregroundColorSpan, (Integer)map.get("startIndex"), (Integer)map.get("endIndex"), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			}
		}
		return spannable;
	}
	
	public static SpannableString decorateRefersInStr(SpannableString spannable,List<Map<String,Object>> list,Resources resources){
		int size = list.size();
		CharacterStyle foregroundColorSpan=new ForegroundColorSpan(Color.argb(255, 33, 92, 110));
		if(list!=null&&list.size()>0){
			for(int i=0;i<size;i++){
				Map<String,Object> map = list.get(i);
				spannable.setSpan(foregroundColorSpan, (Integer)map.get("startIndex"), (Integer)map.get("endIndex"), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			}
		}
		return spannable;
	}
}
